
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<link rel=stylesheet href='include/hoj.css' type='text/css'>
</head>
<body>
<center>
<div style="width:90%; text-align:left">
<img src="image/logo.png"/>
</div>
<table width=96%> 
	<tr align="center" class='hd' valign="top">
				<th><a href="faqs.php">F.A.Qs</a></th>
		<th><a href="./bbs.php">Web Board</a></th>
		<th><a href="./">Home</a></th>
		<th><a href="./problemset.html">ProblemSet</a></th>
		<th><a href="./status.php">Status</a></th>
		<th><a href="./ranklist.php">Ranklist</a></th>
		<th><a href="./contest.php">Contest</a></th>
		<th><a href=loginpage.php>Login</a></th><th><a href=registerpage.php>Register</a></th>	</tr>
</table>
</center>
<center>
<div class="notice">
	<div>
		<B>Notice:</B>鉴于种种原因，本OJ自下周星期一（3月5号）开始不再全面开放，请各位做好善后事宜，谢谢合作。	</div>
</div>
</center>
</div>
<title>Problem 1704. -- [Usaco2007 Mar]Face The Right Way -- 衡阳八中OJ离线版-2012-02-29</title><center><h2>1704: [Usaco2007 Mar]Face The Right Way</h2><span class=green>Time Limit: </span>5 Sec&nbsp;&nbsp;<span class=green>Memory Limit: </span>64 MB<br><span class=green>Submit: </span>90&nbsp;&nbsp;<span class=green>Solved: </span>61<br>[<a href='submitpage.php?id=1704'>Submit</a>][<a href='problemstatus.php?id=1704'>Status</a>][<a href='bbs.php?id=1704'>Discuss</a>]</center><h2>Description</h2><div class=content>Farmer John has arranged his N (1 <= N <= 5,000) cows in a row and
many of them are facing forward, like good cows, Some of them are
facing backward, though, and he needs them all to face forward to
make his life perfect.

Fortunately, FJ recently bought an automatic cow turning machine.
Since he purchased the discount model, it must be irrevocably preset
to turn K (1 <= K <= N) cows at once, and it can only turn cows
that are all standing next to each other in line. Each time the
machine is used, it reverses the facing direction of a contiguous
group of K cows in the line (one cannot use it on fewer than K cows,
e.g., at the either end of the line of cows). Each cow remains in
the same *location* as before, but ends up facing the *opposite
direction*.  A cow that starts out facing forward will be turned
backward by the machine and vice-versa.

Because FJ must pick a single, never-changing value of K, please
help him determine the minimum value of K that minimizes the number of
operations required by the machine to make all the cows face forward.
Also determine M, the minimum number of machine operations required
to get all the cows facing forward using that value of K.

给定一个01序列，固定一个k值和一个m值，即每次给k个连续的数取反
，操作m次后要求数列全部为0，要求最小的m和最小m下最小的k</div><h2>Input</h2><div class=content>* Line 1: A single integer: N

* Lines 2..N+1: Line i+1 contains a single character, F or B,
        indicating whether cow i is facing forward or backward.

</div><h2>Output</h2><div class=content>* Line 1: Two space-separated integers: K and M
</div><h2>Sample Input</h2>
			<div class=content><span class=sampledata>7<br />
B<br />
B<br />
F<br />
B<br />
F<br />
B<br />
B<br />
<br />
INPUT DETAILS:<br />
<br />
There are seven cows and they are facing backward, backward, forward,<br />
backward, forward, backward, and backward, respectively.<br />
</span></div><h2>Sample Output</h2>
			<div class=content><span class=sampledata>3 3<br />
<br />
OUTPUT DETAILS:<br />
<br />
For K = 3, the machine must be operated three times: turn cows (1,2,3),<br />
(3,4,5), and finally (5,6,7):<br />
<br />
      B > F   F   F<br />
      B > F   F   F<br />
      F > B > F   F<br />
      B   B > F   F<br />
      F   F > B > F<br />
      B   B   B > F<br />
      B   B   B > F<br />
</span></div><h2>HINT</h2>
			<div class=content><p></p></div><h2>Source</h2>
			<div class=content><p><a href='problemset.html?search=Gold'>Gold</a></p></div><center>[<a href='submitpage.php?id=1704'>Submit</a>][<a href='problemstatus.php?id=1704'>Status</a>][<a href='bbs.php?id=1704'>Discuss</a>]</center>﻿<br>

<a href="./"><span class=red>HOME</span></a>
<a href="javascript:history.go(-1)"><span class=red>Back</span></a>

<hr>
<center>
	<div class="footer">
			<a href=setlang.php?lang=ko>한국어</a>&nbsp;
		<a href=setlang.php?lang=cn>中文</a>&nbsp;
		<a href=setlang.php?lang=fa>فارسی</a>&nbsp;
		<a href=setlang.php?lang=en>English</a>&nbsp;
		<a href=setlang.php?lang=th>ไทย</a>
	<br>		<div>版权所有 &copy;2008-2012 WaterPark Organization. | <script src="http://s21.cnzz.com/stat.php?id=2982771&web_id=2982771" language="JavaScript"></script>
</div>
		<div>Based on opensource project <a href="http://hustoj.googlecode.com">hustoj</a>.</div>
	</div>
</center>
</body>
</html>
